package com.taotao.chain.factory;

import com.taotao.chain.GatewayHandler;
import com.taotao.chain.impl.BlackLimitHandler;
import com.taotao.chain.impl.ConversationLimitHandler;
import com.taotao.chain.impl.CurrentLimitHandler;
import com.taotao.utils.SpringUtils;

/**
 * @Author: wangjin
 * @CreateTime: 2022-06-25  23:32
 */
public class FactoryHandler {
    public static GatewayHandler getGatewayHandler() throws Exception {
       /* CurrentLimitHandler currentLimitHandler=new CurrentLimitHandler();
        //1 设置黑名单BlackListHandler
        BlackLimitHandler blackLimitHandler=new BlackLimitHandler();
       blackLimitHandler.setNextGatewayHandler(new ConversationLimitHandler());
        //2 设置api接口限流的handler下一个handler黑名单Handler
        currentLimitHandler.setNextGatewayHandler(blackLimitHandler);*/
        ConversationLimitHandler conversationLimitHandler = SpringUtils.getBean("conversationLimitHandler", ConversationLimitHandler.class);
        BlackLimitHandler blackLimitHandler = SpringUtils.getBean("blackLimitHandler", BlackLimitHandler.class);
        blackLimitHandler.setNextGatewayHandler(conversationLimitHandler);
        // 2.设置api接口限流的Handler 下一个Handler 黑名单Handler
        CurrentLimitHandler currentLimitHandler = SpringUtils.getBean("currentLimitHandler", CurrentLimitHandler.class);
        currentLimitHandler.setNextGatewayHandler(blackLimitHandler);
        return currentLimitHandler;
    }

    public static void main(String[] args) throws Exception {
         GatewayHandler gatewayHandler=FactoryHandler.getGatewayHandler();
         gatewayHandler.doServices();
    }
}
